# Contributor: Roland Kammerer <roland.kammerer@linbit.com>
# Maintainer: Roland Kammerer <roland.kammerer@linbit.com>

# when changing _ver we *must* bump _rel
_name=drbd
_ver=9.0.22-2
_rel=0

_flavor=${FLAVOR:-lts}
_kpkg=linux-$_flavor
_kver=5.4.58
_krel=0
_kabi="$_kver-$_krel-$_flavor"
_kpkgver="$_kver-r$_krel"

pkgname=$_name-$_flavor
pkgver=$_kver
pkgrel=$(( $_krel + $_rel ))

pkgdesc="Network-based RAID 1 version 9"
url="https://www.linbit.com/en/drbd-community/drbd-download/"
arch="all !armhf"
license="GPL-2.0-or-later"
depends="$_kpkg=$_kpkgver"
makedepends="$_kpkg-dev=$_kpkgver bash coreutils"
source="http://www.linbit.com/downloads/drbd/${_ver%.*}/drbd-$_ver.tar.gz"

builddir=$srcdir/$_name-$_ver

prepare() {
	default_prepare
	# verify the kernel version
	local _kapkbuild=../../main/linux-$_flavor/APKBUILD
	if [ -f $_kapkbuild ]; then
		(	. $_kapkbuild
			pkgname=$_name-$_flavor
			[ "$_kver" != "$pkgver" ] && die "please update _kver to $pkgver"
			[ "$_krel" != "$pkgrel" ] && die "please update _krel to $pkgrel"
			return 0
		)
	fi
}

build() {
	cd "$builddir"
	unset LDFLAGS
	make KVER=$_kabi
}

package() {
	cd "$builddir"
	make DESTDIR="$pkgdir" install
}

sha512sums="ddb3ad0a83cbd07eaa178168c9fea74999a5577ccc94164c0ca3c6a41a50d67944533b82957ccd8ad8bf6adacc116774fb978497c15ac54b8d8c780b97face20  drbd-9.0.22-2.tar.gz"
